home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Hello / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  7.2 KB  |  251 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Frame.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Hello.hpp"
  11.  
  12. #ifndef FRAME_H
  13. #include "Frame.h"
  14. #endif
  15.  
  16. #ifndef PART_H
  17. #include "Part.h"
  18. #endif
  19.  
  20. #ifndef COMMANDS_H
  21. #include "Commands.h"
  22. #endif
  23.  
  24. #ifndef CONTENT_H
  25. #include "Content.h"
  26. #endif
  27.  
  28. // ----- Framework Layer -----
  29.  
  30. #ifndef FWCONTXT_H
  31. #include "FWContxt.h"
  32. #endif
  33.  
  34. #ifndef FWPRESEN_H
  35. #include "FWPresen.h"
  36. #endif
  37.  
  38. #ifndef FWSELECT_H
  39. #include "FWSelect.h"
  40. #endif
  41.  
  42. #ifndef FWGROWBX_H
  43. #include "FWGrowBx.h"
  44. #endif
  45.  
  46. #ifndef FWSCLBAR_H
  47. #include "FWSclBar.h"
  48. #endif
  49.  
  50. // ----- OS Layer -----
  51.  
  52. #ifndef FWMENU_H
  53. #include "FWMenu.h"
  54. #endif
  55.  
  56. #ifndef FWEVENT_H
  57. #include "FWEvent.h"
  58. #endif
  59.  
  60. // ----- Graphics Includes -----
  61.  
  62. #ifndef FWRECT_H
  63. #include "FWRect.h"
  64. #endif
  65.  
  66. #ifndef FWTXTBOX_H
  67. #include "FWTxtBox.h"
  68. #endif
  69.  
  70. #ifndef FWRECSHP_H
  71. #include "FWRecShp.h"
  72. #endif
  73.  
  74. // ----- OpenDoc Includes -----
  75.  
  76. #ifndef SOM_Module_OpenDoc_StdProps_defined
  77. #include <StdProps.xh>
  78. #endif
  79.  
  80. #ifndef SOM_ODDragItemIterator_xh
  81. #include <DgItmIt.xh>
  82. #endif
  83.  
  84. //========================================================================================
  85. // Runtime Information
  86. //========================================================================================
  87.  
  88. #ifdef FW_BUILD_MAC
  89. #pragma segment odfhello
  90. #endif
  91.  
  92. FW_DEFINE_AUTO(CHelloFrame)
  93.  
  94. //========================================================================================
  95. // CHelloFrame class
  96. //========================================================================================
  97.  
  98. //----------------------------------------------------------------------------------------
  99. // CHelloFrame constructor
  100. //----------------------------------------------------------------------------------------
  101. CHelloFrame::CHelloFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CHelloContent* content) :
  102.     FW_CFrame(ev, odFrame, presentation, content->GetPart(ev)),
  103.     FW_MDraggableFrame(ev, this),
  104.     FW_MDroppableFrame(ev, this),    
  105.     fHelloContent(content)
  106. {
  107. }
  108.  
  109. //----------------------------------------------------------------------------------------
  110. // CHelloFrame destructor
  111. //----------------------------------------------------------------------------------------
  112.  
  113. CHelloFrame::~CHelloFrame()
  114. {
  115. }
  116.  
  117. //----------------------------------------------------------------------------------------
  118. //    CHelloFrame::DoMouseDown
  119. //----------------------------------------------------------------------------------------
  120.  
  121. FW_Handled CHelloFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  122. {
  123.     FW_Handled result = FW_kNotHandled;
  124.  
  125.     if (GetPresentation(ev)->GetSelection(ev)->IsMouseInDraggableItem(ev, this, theMouseEvent, FALSE) &&
  126.        this->Drag(ev, theMouseEvent)) 
  127.     {
  128.         result = FW_kHandled;
  129.     }
  130.  
  131.     return result;
  132. }
  133.  
  134. //----------------------------------------------------------------------------------------
  135. // CHelloFrame::DoAdjustMenus
  136. //----------------------------------------------------------------------------------------
  137.  
  138. FW_Handled CHelloFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  139.                                       FW_Boolean hasMenuFocus,
  140.                                       FW_Boolean isRoot)    // Override
  141. {
  142. FW_UNUSED(isRoot);
  143.     if (hasMenuFocus)
  144.         menuBar->EnableCommand(ev, kODCommandPaste, HasSupportedKindOnClipboard(ev));
  145.     
  146.     return FW_kNotHandled;
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. // CHelloFrame::Draw
  151. //----------------------------------------------------------------------------------------
  152.  
  153. void CHelloFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  154. {
  155.     FW_CViewContext fc(ev, this, odFacet, invalidShape);
  156.     FW_CRect invalidRect;
  157.     fc.GetClipRect(invalidRect);
  158.  
  159.     FW_CRectShape::RenderRect(fc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  160.  
  161.     FW_CRect helloRect = GetBounds(ev);
  162.  
  163.     FW_CRectShape::RenderRect(fc, helloRect, FW_kFrame, FW_CInk(FW_kRGBBlack));
  164.  
  165.     // If this is a root part, draw the text centered horizontally and vertically.
  166.     // If it's an embedded part, center the text horizontally, with word wrap and clipping.
  167.     FW_TextBoxOptions options = FW_kTextBoxJustifyHCenter | FW_kTextBoxJustifyVCenter;
  168.     if (!fHelloContent->IsTextCentered())
  169.     {
  170.         options |= FW_kTextBoxWordWrap;
  171.         options |= FW_kTextBoxClipToBox;
  172.     }
  173.     FW_CTextBoxShape::RenderTextBox(
  174.         fc,
  175.         fHelloContent->GetTextData(),
  176.         helloRect,
  177.         FW_kSystemFont,
  178.         options);
  179. }
  180.  
  181. //----------------------------------------------------------------------------------------
  182. // CHelloFrame::FrameShapeChanged
  183. //----------------------------------------------------------------------------------------
  184. // By default an FW_CFrame view is not refreshed entirely when resized.
  185. // You must decide if your content's appearance depends on the frame's size.
  186. // If it doesn't you don't need to override FrameShapeChanged().
  187. // Here we must redraw the whole frame everytime because the text is centered.
  188.  
  189. void CHelloFrame::FrameShapeChanged(Environment* ev)
  190. {
  191.     FW_CFrame::FrameShapeChanged(ev);
  192.     
  193.     this->Invalidate(ev);
  194. }
  195.  
  196. //----------------------------------------------------------------------------------------
  197. //    CHelloFrame::NewClipboardCommand
  198. //----------------------------------------------------------------------------------------
  199.  
  200. FW_CClipboardCommand* CHelloFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  201. {
  202.     return FW_NEW(CHelloEditCommand, (ev, commandID, fHelloContent, this));
  203. }
  204.  
  205. //----------------------------------------------------------------------------------------
  206. //    CHelloFrame::NewDragCommand
  207. //----------------------------------------------------------------------------------------
  208.  
  209. FW_CDragCommand* CHelloFrame::NewDragCommand(Environment* ev, 
  210.                                              FW_CFrame* theFrame,
  211.                                              const FW_CMouseEvent& theMouseEvent)
  212. {
  213. FW_UNUSED(theMouseEvent);
  214.     return FW_NEW(CHelloDragCommand, (ev, fHelloContent, theFrame));
  215. }
  216.  
  217. //----------------------------------------------------------------------------------------
  218. //    CHelloFrame::NewDropCommand
  219. //----------------------------------------------------------------------------------------
  220.  
  221. FW_CDropCommand* CHelloFrame::NewDropCommand(Environment* ev,
  222.                                              FW_CFrame* frame,
  223.                                              ODDragItemIterator* dropInfo, 
  224.                                              ODFacet* odFacet, 
  225.                                              const FW_CPoint& dropPoint)
  226. {
  227. FW_UNUSED(frame);
  228.     return FW_NEW(CHelloDropCommand, (ev, fHelloContent, this, dropInfo, odFacet, dropPoint));
  229. }
  230.  
  231. //----------------------------------------------------------------------------------------
  232. //     CHelloFrame::CreateSubViews
  233. //----------------------------------------------------------------------------------------
  234.  
  235. void CHelloFrame::CreateSubViews(Environment* ev)
  236. {        
  237.     // Create a GrowBox only in a root frame
  238.     // Note: you do not need CreateSubViews if the views are defined in resources.
  239.     //        See the Container or Form samples.
  240.     
  241.     if (this->IsRoot(ev)) 
  242.     {
  243.         FW_CRect frameRect = GetBounds(ev);  
  244.         FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  245.         frameRect.right -= sbSize.x;
  246.         frameRect.bottom -= sbSize.y;
  247.         
  248.         FW_CGrowBox* growBox = new FW_CGrowBox(ev, this, 0, frameRect.BotRight());
  249.     }
  250. }
  251.